<template>
    <view class="content">
        <view class="u-p-b-20">
            <u-search :show-action="false" shape="round" placeholder="请输入陪伴师姓名" bg-color="#fff"
                v-model="keyword" @search="doSearch"></u-search>
        </view>
        
        <view class="item" v-for="(item, index) in list" :key="index" @click="$gTo(`/mine/pages/service/service-details?id=${item.id}`)">
            <image :src="item.image" class="avatar"></image>
            <view class="u-flex-1">
                <view class="item-r-t">
                    <view class="name">{{item.name}}</view>
                    <view class="real">已实名</view>
                    <u-rate :count="item.star" v-model="item.star" active-color="#fec427" size="26" gutter="5" disabled></u-rate>
                    <!-- <u-icon name="star-fill" color="#fec427" size="28"></u-icon> -->
                    <!-- <view class="star-num">{{item.star}}</view> -->
                </view>
                <view class="great">擅长：{{item.be_good_at}}</view>
            </view>
            <view class="btn">查看详情</view>
        </view>
        
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
                keyword:'',
            };
        },
        onLoad() {
            this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
            doSearch() {
                this.list = []
                this.page = 1
                this.status = 'loadmore'
                this.getList()
            },
            
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('recommend_service', {
            		user_token: this.$getSync('userToken'),
            		page: this.page,
            		limit: 10,
                    name: this.keyword,
            	}).then(ret => {
            		if (ret.success == 1000) {
            			if (ret.detail && ret.detail.service && ret.detail.service.length > 0) {
            				this.list = this.list.concat(ret.detail.service);
            				this.page++;
            				this.status = 'loadmore'
            			} else {
            				this.status = 'nomore'
            			}
            		} else {
            			this.$toast(ret.msg);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    page{
        background-color: #f5f5f5;
    }
    .content{
        padding: 20rpx;
    }
    .item{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 30rpx 20rpx;
        background-color: #fff;
        border-radius: 20rpx;
        margin-bottom: 20rpx;
    }
    .avatar{
        width: 95rpx;
        height: 95rpx;
        border-radius: 50%;
        margin-right: 20rpx;
    }
    .item-r-t{
        display: flex;
        justify-content: flex-start;
        align-items: center;
    }
    .name{
        max-width: 175rpx;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 32rpx;
        font-weight: bold;
    }
    .real{
        padding: 7rpx 8rpx;
        background-color: #000;
        border-radius: 6rpx;
        font-size: 20rpx;
        color: #feeca8;
        line-height: 1;
        margin: 0 10rpx;
    }
    .star-num{
        font-size: 28rpx;
        font-weight: bold;
        padding-left: 6rpx;
    }
    .great{
        font-size: 24rpx;
        color: #949494;
        padding-top: 10rpx;
        width: 400rpx;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .btn{
        font-size: 25rpx;
        color: #fff;
        padding: 12rpx 16rpx;
        background-color: #f29700;
        border-radius: 10rpx;
    }

</style>
